Skip to content

Kill an incumbent daemon that ignores SIGTERM - #13

Merged
TerrifiedBug merged 1 commit into
mainfrom
fix/kill-wedged-incumbent
Aug 21, 2026
Merged

Kill an incumbent daemon that ignores SIGTERM#13
TerrifiedBug merged 1 commit into
mainfrom
fix/kill-wedged-incumbent

Conversation

@TerrifiedBug

Copy link
Copy Markdown
Owner

Follow-up to #12, which got this branch wrong.

The five-second wait ended in return false — "leaving it the hotkey". It cannot leave it the hotkey: the SIGTERM was delivered before the wait started, so the incumbent dies the moment it is unwedged, and the newcomer has already exited. The real outcome was zero daemons, described by a log line saying the old one still had it.

Escalate to SIGKILL instead. Anything still holding the lock five seconds after a SIGTERM is wedged rather than busy — a clean exit is a few file writes — and the kernel releases the lock with the process, so the newcomer takes it. One daemon either way, which is the entire point of the lock. If the one killed was the login job, launchd sees the abnormal exit and brings it back; it then finds the lock held and the two settle it the ordinary way, so one of them ends up holding it and never both.

Only a signal the kernel refuses (kill failing with something other than ESRCH) still ends in return false.

Verification

Incumbent frozen with kill -STOP so it cannot answer SIGTERM, then a second daemon started:

another yap daemon has the hotkey (pid 60562) — replacing it
pid 60562 ignored SIGTERM — killing it
loading parakeet-tdt-ctc-110m...
✓ parakeet-tdt-ctc-110m ready
listening on fn hold · parakeet-tdt-ctc-110m · …

The frozen pid is gone and exactly one process is left listening. Previously the same test left the newcomer dead, the frozen daemon doomed, and nothing on the hotkey.

The five-second wait ended by giving up, which cannot be what happens:
the SIGTERM has already been delivered by then, so the incumbent dies as
soon as it is unwedged, and the newcomer has just exited. The outcome was
zero daemons and a log line claiming the old one still had the hotkey.

Escalate to SIGKILL instead. Anything still holding the lock five seconds
after a SIGTERM is wedged rather than busy — a clean exit is a few file
writes — and the kernel drops the lock with the process, so the newcomer
takes it and there is exactly one daemon either way. If the one killed
was the login job, launchd brings it back and the two settle it the
ordinary way; one of them holds the lock, never both.

Verified: incumbent frozen with SIGSTOP, second daemon started — logs
"ignored SIGTERM — killing it", the frozen pid is gone, and one process
is left listening.
@TerrifiedBug
TerrifiedBug merged commit 247c0da into main Aug 21, 2026
1 check passed
@TerrifiedBug
TerrifiedBug deleted the fix/kill-wedged-incumbent branch August 21, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant